﻿#pragma once
#include <stdint.h>
#include <string>
#include <list>
#include "base/core/point2.h"
#include "base/core/point3.h"
#include "base/core/knode.h"
#include "ConfigDefine.h"
#include "Common/SceneDefine.h"
//#include "Common/EventDefine.h"

#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable:4512) //assignment operator could not be generated
#pragma warning(disable:4244) //conversion from '__int64' to 'int', possible loss of data
#pragma warning(disable:4267) //conversion from 'size_t' to 'int', possible loss of data
#pragma warning(disable:4127) //conditional expression is constant
#endif
#include "Common/ComDefine.pb.h"
#include "ProtoBuffer/ComProtocol.pb.h"
#ifdef _MSC_VER
#pragma warning(pop)
#endif

#pragma pack(push)
#pragma pack(1)


typedef uint64_t  CharIDType;

using namespace ProtoBuf;

//���߽�ɫ������󻺴�ʱ��
#define MAX_OFFLINE_CHARACTER_DATA_CACHE_SEC (7*24*3600)
#define MAX_CHARACTER_SINGLERANGE  60      //视野
#define MAX_CHARACTER_SINGLERANGE_SQUARE 3600
#define MAX_POS_ALLOW_ERROR			25		  //允午距离最大误差 
//grid count (100-200)*(100-200)
#define GRID_LENGTH 20   //和视野是1:3的关系

// ȫ�ֻ��棬�ɱ�����
struct CharacterCacheData
{
    uint64_t	lastOnlineTime;                // 0��ʾ����
	char		name[NAME_LENGTH_32];
	int			level;
	int			fightPower;

	CharacterCacheData()
	{
        lastOnlineTime = 0;
		memset(name, 0, sizeof(name));
		level = 0;
		fightPower = 0;
    }
};

struct CharacterInfo
{
	CharIDType	id;						// ������id
	char        name[NAME_LENGTH_32];	// ����
    uint16_t	level;					// �ȼ�

	CharacterInfo()
	{
		id = 0;
        memset(name, 0, sizeof(name));
		level = 1;
    }
};

struct AttributeInfo
{
    int32_t		hp;                     // ����
	int32_t     attack;                 // ����
	int32_t     defense;                // ����

    AttributeInfo()
	{
        hp		= 0;
		attack	= 0;
		defense = 0;
    }
};

struct CharacterAttribute : AttributeInfo
{
    int32_t curHp;						// ��ǰ����

    CharacterAttribute()
	{
        curHp = 0;
    }
};

struct CharacterPosInfo
{
	Point3<float> pos;
    float         dir;

    CharacterPosInfo()
	{
        dir = 0.0f;
    }
};

struct MoveTrace
{
    Point2<float> startPos;             // ��¼��ʼ��λ��
    float         moveDistance;         // ���ƶ�����
    float         leftDistance;         // ����ǽ��ԭ����δ��ɵ��ƶ��ܾ���
    float         maxSpeed;             // �ƶ������г��ֵ�����ٶ�
    uint64_t      fixPosClientTick;     // ��һ���޸��ͻ�������ʱ�Ŀͻ���tick,stateΪrun������²�ʹ��
    uint64_t      fixPosServerTick;     // ��һ���޸��ͻ�������ʱ�ķ���˹�ȥʱ��tick
    float         hitWallTangentDir;    // ��ǽ�ߵ�����dir
    bool          stopMove;             // ��ǽ���޷���������

    MoveTrace()
	{
        moveDistance      = 0.0f;
        leftDistance      = 0.0f;
        maxSpeed          = 0.0f;
        fixPosClientTick  = 0;
        fixPosServerTick  = 0;
        hitWallTangentDir = 0.0f;
        stopMove          = false;
    }
};

struct HitWallParam
{
    float         tangentDir;			// �ƶ���ǽ���߷���
    float         hitLength;			// �ƶ���ǽʣ�����
    float         hitPos[3];			// ��ǽ��λ��
    unsigned int  hitRef;				// ����λ��PolyRef
    unsigned int* pathPolys;			// ������poly
    int           polyCount;			// ������poly����

    void Clear() 
	{
        tangentDir = 0.0f;
        hitLength = 0.0f;
        hitPos[0] = 0.0f;
        hitPos[1] = 0.0f;
        hitPos[2] = 0.0f;
        hitRef    = 0;
        pathPolys = nullptr;
        polyCount = 0;
    }

    HitWallParam() 
	{
        Clear();
    }
};

typedef std::vector<Point3<float>> VEC_POINT3;
typedef std::vector<int> VEC_FLAGS;

struct AutoPathInfo
{
    int         step;    
    float       stepMoveLength;
    bool        isAutoPath;
    bool        arriveCallBack;
    VEC_POINT3  pathList;
    VEC_FLAGS   flagList;

    const Point3<float>& GetStartPosition() 
	{
        MMO_ASSERT(pathList.size() > 0);
        return pathList[0];
    }

    const Point3<float>& GetEndPosition() 
	{
		MMO_ASSERT(pathList.size() > 0);
        return pathList[pathList.size() - 1];
    }

    const Point3<float>& GetCornerPosition(int _step) 
	{
		MMO_ASSERT(_step >= 0 && _step < (int)pathList.size());
        return pathList[_step];
    }

    int GetFlag(int _step) 
	{
		MMO_ASSERT(_step >= 0 && _step < (int)flagList.size());
        return flagList[_step];
    }

    bool IsLastPosition()
	{
        bool result = false;
        if (step >= (int)pathList.size() - 1)
		{
            result = true;
        }
        return result;
    }

    void Clear() 
	{
        step            = 0;
        stepMoveLength  = 0.0f;
        isAutoPath      = false;
        arriveCallBack  = false;
        pathList.clear();
    }

    AutoPathInfo() 
	{
        Clear();
    }
};

class HostNode : public KNode
{
protected:
	void* m_host;

public:
	HostNode() 
		: m_host(nullptr)
	{}

	void* GetHost() 
	{
		return m_host;
	}

	void SetHost(void* host) 
	{
		m_host = host;
	}
};


struct CharLoginInfo
{
	uint32_t reqid;
	uint32_t sceneid;
	uint32_t mapid;
	uint32_t clientId;
	uint32_t gateId;
	uint32_t channelId;
	float x;
	float y;
	float z;
	uint32_t uid;
	CharLoginSyncCenterData protoLogin;
	PlayerSellBackItem sellItem;
	STransParam transParam;
	uint32_t finishFlag;//是否完成新手引导副本
	uint32_t finishStep;//新手引导副本最近完成的步骤
	uint32_t guideDupId;//新手引导副本ID
	CharLoginInfo()
	{
		reqid = 0;
		sceneid = 0;
		mapid = 0;
		x = 0.0f;
		y = 0.0f;
		z = 0.0f;
		clientId = 0;
		uid = 0;
		gateId = 0;
		channelId = 0;
		finishFlag = 0;
		finishStep = 0;
		guideDupId = 0;
	}
};

enum BroadcastOption
{
    emBroadcastNull              = 0,       // ��ͬ��
    emBroadcastAround            = 1,       // �㲥��Χ�Ź�����ȫ�����
    emBroadcastAroundExcludeSelf = 2,       // �㲥��Χ�Ź�����ȫ����ҵ��ų����Լ�
    emBroadcastScene             = 3,       // �㲥��ǰ������ȫ�����
    emBroadcastAll               = 4,       // �㲥ͬLogicServerȫ�����
    emSyncOnlySelf               = 5,       // ֻͬ�����Լ�
};

enum CreatureType
{
	CREATURE_NONE = 0,
	CREATURE_PLAYER,    //�������
	CREATURE_MONSTER,   //�������
	CREATURE_NPC,		//NPC����
	CREATURE_DROP,		//��������
	CREATURE_SUMMON,	//�ٻ���
	CREATURE_PET,		//����ϵͳ,����
	CREATURE_REBOT,     //������
	CREATURE_OBJECT,	//�ɼ���
	CREATURE_MAX
};

enum PartType
{
	PART_NONE = 0,
	PART_OPERATELIMIT,	//统计(需要放到最前面,通过订阅事件统计的数据提供给其他部件使用)
	PART_MOVE,          //�ƶ�����
	PART_BUFF,          //buff����
	PART_SKILL,         //���ܲ���
	PART_PACKAGE,		//��������
	PART_MISSION,		//���񲿼�
	PART_CHAT,			//���첿��
	PART_DUPLICATE,		//��������
	PART_ACHIEVEMENT,	//�ɾͲ���
	PART_PVP,			//PVP����
	PART_DEPUTY,		//��ҵ����
	PART_TREASURE,		//�ڱ�����
	PART_COLLECT,		//�ɼ�����
	PART_RUNBUSINESS,	//���̲���
	PART_TITLE,			//�ƺŲ���
	PART_WELFARE,		//��������
	PART_HUOYUEDU,		//��Ծ�Ȳ���
	PART_HORSE,
	PART_GOD,			//神格
	PART_PANDOS,
	PART_PAY,           //充值
	PART_ADVENTURE,		//奇遇
	PART_MAX,
};

enum enSkillType
{
	enSkillType_None = 0,
	enSkillType_Nomal = 1, //��ͨ����
	enSkillType_SanBi = 2,	//���ܼ���
	enSkillType_Skill1 =3,  //�ĸ�λ�õļ���
	enSkillType_Skill2 = 4,
	enSkillType_Skill3 = 5,
	enSkillType_Skill4 = 6,
};

#pragma pack(pop)